/*
 * 四川生学教育科技有限公司
 * Copyright (c) 2015-2025 Founder Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Founder. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Founder.
 *
 */
package com.example.springboot.service.impl;

import com.example.springboot.mapper.UserMapper;
import com.example.springboot.pojo.User;
import com.example.springboot.service.StudentService;
import org.beetl.sql.core.DSTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;

/**
 * @author JiuHu.XIONG (xjh@sxw.cn)
 * @description TODO
 * @date 2018/9/20 10:23
 * @since 1.0.0
 */
@Component
public class StudentServiceImpl implements StudentService {

    @Autowired
    private UserMapper userMapper;


    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public String hello() throws SQLException {
        DSTransactionManager.start();
        User user1  = new User();
        user1.setUsername("zhangsan1");
        userMapper.insert(user1);

        int i = 1/0;

        User user2  = new User();
        user2.setUsername("zhangsan2");
        userMapper.insert(user2);
        DSTransactionManager.commit();
        return "ffff";
    }
}
